package com.xysoft.admin.web;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xysoft.admin.service.IAdministratorService;
import com.xysoft.util.JsonUtil;

@Controller
@RequestMapping(value = "/admin/administrator.jspx")
public class AdministratorController extends BaseController{
	private IAdministratorService administratorService;
	
	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.administratorService.get(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indexOFsystemType")
	public String getSystemType(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.administratorService.getSystemType(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indexOForgan")
	public String getOrgan(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.administratorService.getOrgan(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "config")
	@ResponseBody
	public Map<String,? extends Object> config(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.administratorService.config(request, session);
	}
	
	@RequestMapping(params = "configOFauto")
	@ResponseBody
	public Map<String,? extends Object> getAuto(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.administratorService.getAuto(request, session);
	}
	
	@RequestMapping(params = "configOFaction")
	public String getAction(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.administratorService.getAction(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "configOFrole")
	public String getRole(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.administratorService.getRole(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "edit")
	public String edit(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws Exception {
		response.setContentType("text/html; charset=UTF-8");
		Map<String, Object> obj = this.administratorService.addOrModify(request, session);
		response.getWriter().print(JsonUtil.toStringFromObject(obj));
		return null;
	}
	
	@RequestMapping(params = "editOFpic")
	public String pic(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws Exception {
		response.setContentType("text/html; charset=UTF-8");
		Map<String, Object> obj = this.administratorService.pic(request, session);
		response.getWriter().print(JsonUtil.toStringFromObject(obj));
		return null;
	}
	
	@RequestMapping(params = "add")
	public String add(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws Exception {
		response.setContentType("text/html; charset=UTF-8");
		Map<String, Object> obj = this.administratorService.addOrModify(request, session);
		response.getWriter().print(JsonUtil.toStringFromObject(obj));
		return null;
	}
	
	@RequestMapping(params = "remove")
	@ResponseBody
	public Map<String,? extends Object> remove(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.administratorService.remove(request, session);
	}

	@Autowired
	public void setAdministratorService(IAdministratorService administratorService) {
		this.administratorService = administratorService;
	}
}
